<template>
  <div>
    <InnerPageTable ref="valueSetTable" :config="pageTableConfig"> </InnerPageTable>
    <Drawer :title="title" :width="800" :closable="false" v-model="showDrawer">
      <summary-detail :row="row" :type="type" :stage="stage - 1" :fromHistory="true" v-if="showDrawer"></summary-detail>
    </Drawer>
  </div>
</template>

<script>
import summaryDetail from '@/views/menuList/rating/components/summaryDetail'
import { historyColumns } from './historyColumns'
import dataApi from '@/api/formData'

export default {
  data() {
    return {
      type: 0,
      row: {},
      pageTableConfig: {
        loadDataFn: this.getServiceList,
        columns: historyColumns.bind(this)(),
        autoFirst: false //默认 就是 false, 要配置在这里
      },
      showDrawer: false,
      title: '评委维度'
    }
  },
  components: { summaryDetail },
  props: {
    id: {
      type: String,
      default: ''
    },
    parentId: {
      type: String,
      default: ''
    },
    stage: {
      type: Number,
      default: 1
    },
    evaluationTargetTitle: {
      type: String,
      default: ''
    }
  },
  methods: {
    getStageShowWord(stage) {
      return `第${stage}轮评分`
    },
    getServiceList(tableObj) {
      let { responseProcess, param } = tableObj
      dataApi
        .parentPage({
          formIdList: [this.id],
          parentId: this.parentId,
          pageSize: param.commonPageDTO.pageSize,
          currentPage: param.commonPageDTO.currentPage
        })
        .then(res => {
          let { pageSize, total, pageNum, records, pages } = res.data.data
          // 过滤掉大于当前评分阶段的数据,并且是当前评分对象
          const result = records.filter(item => {
            return (
              JSON.parse(item.ext).stage < this.stage && item.evaluationTargetTitle === this.evaluationTargetTitle
            )
          })
          result.forEach(row => {
            const info = JSON.parse(row.ext)
            row.judge = info.judge
            row.score = info.score || '--'
            row.stage = info.stage
            row.showstage = this.getStageShowWord(info.stage)
            row.period = info.period
            row.evaluation_target_record_id = info.evaluation_target_record_id
            row.evaluation_target_title = info.evaluation_target_title
            row.evaluation_target_form_id = info.evaluation_target_form_id
            row.evaluation_target_form_sub_type = info.evaluation_target_form_sub_type
            row.evaluation_target_org = info.evaluation_target_org
            row.is_passed = info.is_passed
            row.contact = row.contact || '--'
            row.phone = row.phone || '--'
            row.email = row.email || '--'
            row._loading = false
            row.children = []
          })
          responseProcess({
            pageNum: pageNum,
            pageSize: pageSize,
            pages: pages,
            records: result || [],
            total: total
          })
        })
    },
    judgesSummary(row) {
      this.row = row
      this.type = 0
      this.showDrawer = true
      this.title = '评委维度'
    },
    indicatorSummary(row) {
      this.row = row
      this.type = 1
      this.showDrawer = true
      this.title = '评分指标维度'
    }
  },
  mounted() {
    this.$refs['valueSetTable'].load()
  }
}
</script>

<style lang="scss" scoped></style>
